package org.sdnstproject.interlayer.interlayerProxy;

import org.projectfloodlight.openflow.protocol.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Strategy {
	private static final Logger log = LoggerFactory.getLogger(Strategy.class);
	/**OpenFlow报文版本*/
	public OFVersion ofVersion;
	/**OpenFlow报文类型*/
	public OFType ofType;
	/**OpenFlow报文子类型*/
	public String childOFType;
	/**对OpenFlow报文的Fuzzing动作*/
	public ACTION action;
	/**OpenFlow报文某字段*/
	public String field;
	/**Fuzzing动作对应的值*/
	public String actionValue;
	
	public Strategy(String ofVersion,String ofType,String childOFType,String action,String field,String actionValue){
		if (ofVersion == "1.0") this.ofVersion = OFVersion.OF_10;
		else this.ofVersion = OFVersion.OF_13;
		this.childOFType = childOFType;
		this.field = field;
		this.actionValue = actionValue;
		switch (action) {
			case "DROP":
				this.action = ACTION.DROP;
				break;
			case "DUPLICATE":
				this.action = ACTION.DUPLICATE;
				break;
			case "DELAY":
				this.action = ACTION.DELAY;
				break;
			case "MODIFY":
				this.action = ACTION.MODIFY;
				break;
		}
		
		switch (ofType) {
			case "HELLO":
				this.ofType = OFType.HELLO;
				break;
			case "ERROR":
				this.ofType = OFType.ERROR;
				break;
			case "ECHO_REQUEST":
				this.ofType = OFType.ECHO_REQUEST;
				break;
			case "ECHO_REPLY":
				this.ofType = OFType.ECHO_REPLY;
				break;
			case "EXPERIMENTER":
				this.ofType = OFType.EXPERIMENTER;
				break;
			case "FEATURES_REQUEST":
				this.ofType = OFType.FEATURES_REQUEST;
				break;
			case "FEATURES_REPLY":
				this.ofType = OFType.FEATURES_REPLY;
				break;
			case "GET_CONFIG_REQUEST":
				this.ofType = OFType.GET_CONFIG_REQUEST;
				break;
			case "GET_CONFIG_REPLY":
				this.ofType = OFType.GET_CONFIG_REPLY;
				break;
			case "SET_CONFIG":
				this.ofType = OFType.SET_CONFIG;
				break;
			case "PACKET_IN":
				this.ofType = OFType.PACKET_IN;
				break;
			case "FLOW_REMOVED":
				this.ofType = OFType.FLOW_REMOVED;
				break;
			case "PORT_STATUS":
				this.ofType = OFType.PORT_STATUS;
				break;
			case "PACKET_OUT":
				this.ofType = OFType.PACKET_OUT;
				break;
			case "FLOW_MOD":
				this.ofType = OFType.FLOW_MOD;
				break;
			case "PORT_MOD":
				this.ofType = OFType.PORT_MOD;
				break;
			case "STATS_REQUEST":
				this.ofType = OFType.STATS_REQUEST;
				break;
			case "STATS_REPLY":
				this.ofType = OFType.STATS_REPLY;
				break;
			case "BARRIER_REQUEST":
				this.ofType = OFType.BARRIER_REQUEST;
				break;
			case "BARRIER_REPLY":
				this.ofType = OFType.BARRIER_REPLY;
				break;
			case "QUEUE_GET_CONFIG_REQUEST":
				this.ofType = OFType.QUEUE_GET_CONFIG_REQUEST;
				break;
			case "QUEUE_GET_CONFIG_REPLY":
				this.ofType = OFType.QUEUE_GET_CONFIG_REPLY;
				break;
			case "GROUP_MOD":
				this.ofType = OFType.GROUP_MOD;
				break;
			case "TABLE_MOD":
				this.ofType = OFType.TABLE_MOD;
				break;
			case "ROLE_REPLY":
				this.ofType = OFType.ROLE_REPLY;
				break;
			case "ROLE_REQUEST":
				this.ofType = OFType.ROLE_REQUEST;
				break;
			case "GET_ASYNC_REQUEST":
				this.ofType = OFType.GET_ASYNC_REQUEST;
				break;
			case "GET_ASYNC_REPLY":
				this.ofType = OFType.GET_ASYNC_REPLY;
				break;
			case "SET_ASYNC":
				this.ofType = OFType.SET_ASYNC;
				break;
			case "METER_MOD":
				this.ofType = OFType.METER_MOD;
				break;
			case "ROLE_STATUS":
				this.ofType = OFType.ROLE_STATUS;
				break;
			case "TABLE_STATUS":
				this.ofType = OFType.TABLE_STATUS;
				break;
			case "REQUESTFORWARD":
				this.ofType = OFType.REQUESTFORWARD;
				break;
			case "BUNDLE_CONTROL":
				this.ofType = OFType.BUNDLE_CONTROL;
				break;
			case "BUNDLE_ADD_MESSAGE":
				this.ofType = OFType.BUNDLE_ADD_MESSAGE;
				break;
			case "CONTROLLER_STATUS":
				this.ofType = OFType.CONTROLLER_STATUS;
				break;
		}
	
		
	}
	
	/**
	 * Fuzzing的动作类型.
	 * <p>定义以下动作类型：
	 * <ul>
	 * 	<li>{@code DROP}}丢弃报文
	 * 	<li>{@code DUPLICATE}重复发送报文
	 * 	<li>{@code DELAY}延时发送报文
	 * 	<li>{@code MODIFY}修改报文后发送
	 * </ul>
	 * */
	public enum ACTION{
		/**When receive packet,drop it*/
		DROP,
		/**When receive packet,repeatedly sending it*/
		DUPLICATE,
		/**When receive packet,delayed sending it*/
		DELAY,
		/**When receive packet,modify and send it*/
		MODIFY,
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("ofVersion:").append(ofVersion).append(",ofType:").append(ofType)
		.append(",childOFType:").append(childOFType).append(",action:").append(action)
		.append(",field:").append(field).append(",actionValue:").append(actionValue);
		return builder.toString();
//		return "ofVersion:"+ofVersion+",ofType:"+ofType+",childOFType:"+childOFType
//				+",action:"+action+",field:"+field+",actionValue:"+actionValue;
	}
}
